package com.ruoyi.web.controller.common.aop;

import cn.hutool.core.util.NumberUtil;
import com.ruoyi.common.exception.base.BaseException;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 通用下载方法切面
 */
@Aspect
@Component
public class DownloadBeforeAdvice  {


    /** 切入点表达式 */
    @Pointcut("execution(* com.ruoyi.web.controller.common.CommonController.resourceDownload(..))")
    public void logPointCut(){}

    //前置通知
    @Before("logPointCut()")
    public void beforeDownload(JoinPoint jp) {
        Object[] paramsArray = jp.getArgs();

//        if(NumberUtil.isInteger(request.getParameter("bookId"))){
//            throw  new BaseException("bookId传参有误，请传输整数类型");
//        }
//        int bookId = Integer.parseInt(request.getParameter("bookId"));
//        tbBookService.addDownLoadCount(bookId);
//        System.out.println(httpServletRequest.getParameter("bookId"));
    }
}
